package com.example.robertluozizhao.framecollectdemo.activity

import android.graphics.Rect
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.util.Log
import android.view.TouchDelegate
import android.view.View
import android.widget.Toast
import com.example.robertluozizhao.framecollectdemo.databinding.ActivityIndicateLayoutBinding
import com.example.robertluozizhao.framecollectdemo.util.Exp.ViewExp
import com.example.robertluozizhao.framecollectdemo.util.Exp.ViewExp.clickExpend

/**
 *
 * <pre>
 *     author: luozz@anjiu-tech.com
 *     time  : 2022/4/1 7:22 下午
 *     desc  :
 * </pre>
 *
 **/
class TouchDelegateActivity : AppCompatActivity() {

    val binding: ActivityIndicateLayoutBinding by lazy {
        ActivityIndicateLayoutBinding.inflate(layoutInflater)
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        initView()
    }

    private fun initView() {


        binding.tvClick.clickExpend(listen = {
            Toast.makeText(
                this,
                "Touch occurred within ImageButton touch region.",
                Toast.LENGTH_SHORT
            ).show()
        },100)

//        binding.tvClick.post {
//            var expandExClick = Rect()
//
//            binding.tvClick.setOnClickListener{
//                Toast.makeText(this,
//                    "Touch occurred within ImageButton touch region.",
//                    Toast.LENGTH_SHORT).show()
//
//            }
//
//            binding.tvClick.getHitRect(expandExClick)
//
//            Log.d("initView_ 1", "initView: top:${ expandExClick.top}" +
//                    ",left:${expandExClick.left}," +
//                    ",right:${expandExClick.right}," +
//                    ",bottom:${expandExClick.bottom}," +
//                    "")
//
//            expandExClick.top -= 200
//            expandExClick.left -= 200
//
//            Log.d("initView_ 2", "initView: top:${ expandExClick.top}" +
//                    ",left:${expandExClick.left}," +
//                    ",right:${expandExClick.right}," +
//                    ",bottom:${expandExClick.bottom}," +
//                    "")
//
//            val touchDelegate = TouchDelegate(expandExClick, binding.tvClick)
//            if (View::class.java.isInstance(binding.tvClick.parent)) {
//                (binding.tvClick.parent as View).touchDelegate = touchDelegate
//            }
//        }
    }
}